package com.health.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.health.pojo.OrderSetting;
import com.health.service.OrderSettingService;

import java.util.ArrayList;
import java.util.List;

public class OrderSettingListener extends AnalysisEventListener<OrderSetting> {

    //服务接口
    private OrderSettingService orderSettingService;
    //读取到的所有数据
    private List<OrderSetting> orderSettingList = new ArrayList<>();

    public OrderSettingListener(OrderSettingService orderSettingService) {
        this.orderSettingService = orderSettingService;
    }

    @Override
    public void invoke(OrderSetting orderSetting, AnalysisContext analysisContext) {
        //将读取到的每一行数据存储到集合中
        orderSettingList.add(orderSetting);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //读完之后，调用服务，添加到数据库中
        orderSettingService.add(orderSettingList);
    }
}